package com.changgou.goods.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.pojo.Template;
import com.changgou.goods.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/template")
public class TemplateController {

    @Autowired
    private TemplateService templateService;

    /***
     * 添加规格参数数据
     * @param template
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Template template){
        try {
            templateService.add(template);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"添加失败");
        }
    }

    /**
     * 根据id删除模板
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        try {
            templateService.deleteById(id);
            return new Result(true,StatusCode.OK,"删除模板成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"删除模板失败");
        }
    }



}
